/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:18 AM
------------------------------------------------------*/
using hou_elearning.Entity;
using hou_elearning.DataAccess;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace hou_elearning.Business
{
    public class SukienslideBRL
    {
        #region Init
        private static string EX_NOT_EXIST="Không Tồn Tại Sukienslide Này";
		private static string EX_STIEUDE_EMPTY="Tiêu đề không được để trống";
		private static string EX_ID_INVALID="PK_iSukienslideID không hợp lệ";
        private static string EX_FK_ITRANGSLIDE_INVALID = "FK_iTrangslide không hợp lệ";

        #endregion
        #region Public Methods
        /// <summary>
        /// Get Sukienslide Theo ID
        /// </summary>
        /// <param name="PK_iSukienslideID">Int64:Sukienslide ID</param>
        /// <returns>SukienslideEntity</returns>        
        public static SukienslideEntity GetOne(Int64 PK_iSukienslideID)
        {
            
			if(PK_iSukienslideID<=0)
				throw new Exception(EX_ID_INVALID);
            return SukienslideDAL.GetOne(PK_iSukienslideID);
        }
        /// <summary>
        /// Get Sukienslide Theo FK_iTrangslideID
        /// </summary>
        /// <param name="PK_iSukienslideID">Int64:Sukienslide ID</param>
        /// <returns>SukienslideEntity</returns>        
        public static List<SukienslideEntity> GetByFK_iTrangslideID(Int64 FK_iTrangslideID)
        {
            if (FK_iTrangslideID <= 0)
                throw new Exception(EX_FK_ITRANGSLIDE_INVALID);
            return SukienslideDAL.GetByFK_iTrangslideID(FK_iTrangslideID);
        }
        /// <summary>
        /// Lấy về List các Sukienslide
        /// </summary>
        /// <returns>List SukienslideEntity:List Sukienslide Cần lấy</returns>
        public static List<SukienslideEntity> GetAll()
        {
            return SukienslideDAL.GetAll();
        }
        
        /// <summary>
        /// Kiểm tra và thêm mới Sukienslide
        /// </summary>
        /// <param name="entity">Entity</param>
        /// <returns>Int64: ID của Sukienslide Mới Thêm Vào</returns>
        public static Int64 Add(SukienslideEntity entity)
        {
            checkLogic(entity);
            checkDuplicate(entity, false);
            checkFK(entity);
            return SukienslideDAL.Add(entity);
        }
        /// <summary>
        /// Kiểm tra và chỉnh sửa Sukienslide
        /// </summary>
        /// <param name="entity">SukienslideEntity</param>
        /// <returns>bool:kết quả thực hiện</returns>
        public static bool Edit(SukienslideEntity entity)
        {
            checkExist(entity.PK_iSukienslideID);
            checkLogic(entity);
            checkDuplicate(entity, true);
            checkFK(entity);
            return SukienslideDAL.Edit(entity);
        }
        /// <summary>
        /// Kiểm tra và xoá Sukienslide
        /// </summary>
        /// <param name="PK_iSukienslideID">Int64 : PK_iSukienslideID</param>
        /// <returns>bool:kết quả thực hiện</returns>
        public static bool Remove(Int64 PK_iSukienslideID)
        {
            checkExist(PK_iSukienslideID);
            return SukienslideDAL.Remove(PK_iSukienslideID);
        }
        #endregion
        #region Private Methods
        private static void checkExist(Int64 PK_iSukienslideID)
        {
            SukienslideEntity oSukienslide=SukienslideDAL.GetOne(PK_iSukienslideID);
            if(oSukienslide==null)
                throw new Exception(EX_NOT_EXIST);
        }
        /// <summary>
        /// Kiểm tra logic Entity
        /// </summary>
        /// <param name="entity">SukienslideEntity: entity</param>
        public static void checkLogic(SukienslideEntity entity)
        {

        }
        /// <summary>
        /// Kiểm tra trùng lặp bản ghi
        /// </summary>
        /// <param name="entity">SukienslideEntity: SukienslideEntity</param>
        private static void checkDuplicate(SukienslideEntity entity,bool checkPK)
        {
            /* 
            Example
            List<SukienslideEntity> list = SukienslideDAL.GetAll();
            if (list.Exists(
                delegate(SukienslideEntity oldEntity)
                {
                    bool result =oldEntity.FIELD.Equals(entity.FIELD, StringComparison.OrdinalIgnoreCase);
                    if(checkPK)
                        result=result && oldEntity.PK_iSukienslideID != entity.PK_iSukienslideID;
                    return result;
                }
            ))
            {
                list.Clear();
                throw new Exception(EX_FIELD_EXISTED);
            }
            */
        }
        /// <summary>
        /// Kiểm tra tồn tại khóa ngoại
        /// </summary>
        /// <param name="entity">SukienslideEntity:entity</param>
        private static void checkFK(SukienslideEntity entity)
        {
            
        }
        #endregion
    }
}
